package 笔试题;

import javafx.util.Pair;

import java.util.Deque;
import java.util.LinkedList;

public class 二叉树的最右下角结点 {

    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
    }


    public static class Solution {
        /**
         * @param root TreeNode类 根节点
         * @return int整型
         */
        public int find(TreeNode root) {
            // write code here
            Deque<TreeNode> deque = new LinkedList<>();
            deque.addLast(root);
            int lastValue = -1;
            while (!deque.isEmpty()) {
                int size = deque.size();
                for (int i = 0; i < size; i++) {
                    TreeNode currNode = deque.pollFirst();
                    if (i == size - 1) lastValue = currNode.val;
                    if (currNode.left != null) deque.addLast(currNode.left);
                    if (currNode.right != null) deque.addLast(currNode.right);
                }
            }
            return lastValue;
        }

        public static void main(String[] args) {
            Pair<Integer, Integer> map = new Pair<>(1, 2);
            int key = map.getKey();
            int value = map.getValue();
        }
    }
}
